home *** CD-ROM | disk | FTP | other *** search
/ Clickx 96 / Clickx 96.iso / software / tools / tool / xbmc-10.1.exe / addons / script.module.pil / lib / PIL / ImageMode.py < prev    next >
Encoding:
Python Source  |  2009-04-06  |  1.3 KB  |  51 lines

  1. #
  2. # The Python Imaging Library.
  3. # $Id$
  4. #
  5. # standard mode descriptors
  6. #
  7. # History:
  8. # 2006-03-20 fl   Added
  9. #
  10. # Copyright (c) 2006 by Secret Labs AB.
  11. # Copyright (c) 2006 by Fredrik Lundh.
  12. #
  13. # See the README file for information on usage and redistribution.
  14. #
  15.  
  16. # mode descriptor cache
  17. _modes = {}
  18.  
  19. ##
  20. # Wrapper for mode strings.
  21.  
  22. class ModeDescriptor:
  23.  
  24.     def __init__(self, mode, bands, basemode, basetype):
  25.         self.mode = mode
  26.         self.bands = bands
  27.         self.basemode = basemode
  28.         self.basetype = basetype
  29.  
  30.     def __str__(self):
  31.         return self.mode
  32.  
  33. ##
  34. # Gets a mode descriptor for the given mode.
  35.  
  36. def getmode(mode):
  37.     if not _modes:
  38.         # initialize mode cache
  39.         import Image
  40.         # core modes
  41.         for m, (basemode, basetype, bands) in Image._MODEINFO.items():
  42.             _modes[m] = ModeDescriptor(m, bands, basemode, basetype)
  43.         # extra experimental modes
  44.         _modes["LA"] = ModeDescriptor("LA", ("L", "A"), "L", "L")
  45.         _modes["PA"] = ModeDescriptor("PA", ("P", "A"), "RGB", "L")
  46.         # mapping modes
  47.         _modes["I;16"] = ModeDescriptor("I;16", "I", "L", "L")
  48.         _modes["I;16L"] = ModeDescriptor("I;16L", "I", "L", "L")
  49.         _modes["I;16B"] = ModeDescriptor("I;16B", "I", "L", "L")
  50.     return _modes[mode]
  51.